package com.lq.educationsystem.lqclasses.controller;

import com.lq.educationsystem.common.util.Result;
import com.lq.educationsystem.common.util.ResultBuild;
import com.lq.educationsystem.common.util.ResultPage;
import com.lq.educationsystem.common.util.ResultPageBuild;
import com.lq.educationsystem.common.vo.ClassesStudentPageVo;
import com.lq.educationsystem.lqclasses.entiy.ClassesStudentTb;
import com.lq.educationsystem.lqclasses.service.ClassesStudentBaseService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Tag(name = "学生课程信息")
@RequestMapping("/classes/student/base")
@RestController
public class ClassesStudentBaseController {
    @Autowired
    ClassesStudentBaseService classesStudentBaseService;
    //增加

    @Operation(summary = "插入学生课程信息")
    @PostMapping("/insert")
    public Result insertClassesStudentInfo(@RequestBody ClassesStudentTb classesStudentInfo){

        classesStudentBaseService.insertInfo(classesStudentInfo);
        return ResultBuild.buildOk();
    }
    //删除
    @Operation(summary = "通过课程学生表id删除")
    @PostMapping("/delete")
    public Result deleteClassesStudentById(@RequestBody ClassesStudentTb classesStudentInfo){
        Integer classesStudentId = classesStudentInfo.getClassesStudentId();
        classesStudentBaseService.deleteById(classesStudentId);
        //删除
        return ResultBuild.buildOk();

    }
    //更新
    @Operation(summary = "更新班级学生表信息")
    @PostMapping("/update")
    public Result updateClassesStudentInfo(@RequestBody ClassesStudentTb classesStudentInfo){
        classesStudentBaseService.updateInfo(classesStudentInfo);
        return ResultBuild.buildOk();
    }
    //通过id查询
    @Operation(summary = "通过学生课程id查询学生信息")
    @PostMapping("/querybyid")
    public Result<ClassesStudentTb> queryClassesStudentById(@RequestBody ClassesStudentTb classesStudentInfo){
        //通过id查询
        Integer classesStudentId = classesStudentInfo.getClassesStudentId();
        Result result=classesStudentBaseService.queryById(classesStudentId);

        return result;
    }
    //查询所有
    @Operation(summary = "分页查询")
    @PostMapping("/query")
    public ResultPage<ClassesStudentTb> queryClassesStudent(@RequestBody ClassesStudentPageVo classesStudentPageVo){

        ResultPage<ClassesStudentTb> classesStudentTbResultPage = classesStudentBaseService.queryList(classesStudentPageVo);
        return classesStudentTbResultPage;
    }
    /**
     * 通过学生id查询信息
     */
    @Operation(summary = "通过学生id查询课程信息")
    @PostMapping("/qclassesbystuentdid")
    public Result<ClassesStudentTb> queryClassesInfoByStudentId (@RequestBody ClassesStudentTb classesStudentInfo ){
         Result<ClassesStudentTb> classesStudentTbResult =  classesStudentBaseService.queryClassesInfoByStudentId(classesStudentInfo);
         return classesStudentTbResult;
    }

    /**
     * 通过班级信息查询数据
     * @param classesStudentPageVo
     * @return
     */
    @Operation(summary = "通过学生id集合批量查询学生课程信息")
    @PostMapping("/qclassesstudentinfobystudentid")
    public ResultPage<ClassesStudentTb> queryBatchClassesStudentInfoByStudentId(@RequestBody ClassesStudentPageVo classesStudentPageVo){
        ResultPage<ClassesStudentTb> classesStudentTbResultPage= classesStudentBaseService.queryBatchClassesStudentInfoByStudentId(classesStudentPageVo);
        return classesStudentTbResultPage;
    }

    /**
     * 通过班级id查询班级内所有学生的id
     */

    @Operation(summary = "通过班级id查询所有的学生id")
    @PostMapping("/query/classes/student")
    public ResultPage<ClassesStudentTb> queryClassesStudentInfoListByClassesId(@RequestBody ClassesStudentPageVo classesStudentPageVo){

        System.out.println("classesStudentPageVo = " + classesStudentPageVo);
        ResultPage<ClassesStudentTb> classesStudentTbResultPage = classesStudentBaseService.queryClassesStudentInfoListByClassesId(classesStudentPageVo);

        return classesStudentTbResultPage;
    }
}
